/**
 * Created by Richard Radlherr.
 * Date: 04.06.2006 17:20
 */
using System;
using System.Collections.Generic;
using System.IO;

namespace TagTool.Core
{

	public abstract class BaseNode
	{
		private String name = "";
		private InputSlot triggerIn;
		private OutputSlot triggerOut;
		
		private int id;
		private static int lastNodeID;
		
		private int x;
		private int y;		
		
		public static void ResetIDCounter()
		{
			lastNodeID = 0;
		}
		
		public BaseNode()
		{
			lastNodeID++;
			this.id = lastNodeID;
			triggerIn = new InputSlot(this, "Trigger in", false);
			triggerIn.Active = true;
			
			triggerOut = new OutputSlot(this, "Trigger out", typeof(bool));
			triggerOut.Value = false;
		}

		
		public int LocY {
			get {
				return y;
			}
			set {
				y = value;
			}
		}
		
		public int LocX {
			get {
				return x;
			}
			set {
				x = value;
				
			}
		}

		public int Id
		{
			get { return id; }
			set 
			{
				id = value;
				lastNodeID = id;
			}
		}
		
		public String Name
		{
			get { return name; }
			set { name = value; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot TriggerIn
		{
			get { return triggerIn; }
		}
		
		[NodeAttribute(SlotType.Output, Show = true)]
		public OutputSlot TriggerOut
		{
			get { return triggerOut; }
		}
		
		public abstract void Update(Object sender);
		
		public void CastTrigger()
		{
			triggerOut.Value = !((bool)triggerOut.Value);
		}
		
		public void SetTrigger(bool value)
		{
			triggerOut.Value = value;
		}

		public override string ToString()
		{
			return name;
		}
		
		protected void OnUpdate(Object sender, EventArgs e)
		{
			this.Update(sender);
		}
		
		public virtual void Initialize()
		{
		}

	}

}
